package edu.zzuli.assistant.service.impl;

import org.hibernate.Session;
import org.hibernate.Transaction;

import edu.zzuli.assistant.bean.Admin;
import edu.zzuli.assistant.dao.AdminDao;
import edu.zzuli.assistant.dao.impl.AdminDaoImpl;
import edu.zzuli.assistant.service.AdminService;
import edu.zzuli.assistant.until.HibernateUtil;

public class AdminServiceImpl implements AdminService {

	private AdminDao adminDao=new AdminDaoImpl();
	
	
	@Override
	public Admin login(Admin admin) {
		Admin result =null;
		try {
			result=adminDao.exists(admin);
		} catch (Exception e) {
			// TODO: handle exception
		}
		finally{
			HibernateUtil.closeSession();
		}
		return result;
	}


	@Override
	public boolean modifyPassword(Admin admin, String newPassword) {
		// TODO Auto-generated method stub
		boolean flag =false;
		Transaction tx = null;
		Session session = null;
		try {
			if(adminDao.exists(admin)!=null){
				session = HibernateUtil.getCurrentSession();
				tx = session.beginTransaction();
				adminDao.modifyPassword(admin, newPassword);
				tx.commit();
				flag =true;
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		finally{
			HibernateUtil.closeSession();
		}
		return flag;
	}
	
}
